def fun1(a):
    def fun2():
        # nonlocal a
        a = 1
        print(a)
    fun2()
    print(a)

fun1(2)

def fun1(a):
    def fun2():
        def fun3():
            nonlocal a
            a = 1
            print(a)
        fun3()
        print(a)
    fun2()
    print(a)
fun1(2)

def fun1(a):
    def fun2():
        nonlocal a
        a = 1
        print(a)
    fun2()
    print(a)

fun1(2)
print(a)